/////////////////////////////////////////////////////////////////////////////
//
//  Fifteen Puzzle
//  Kolonitsky Developers Alliance (c) 2012
//  All rights received
//
/////////////////////////////////////////////////////////////////////////////

package view.skins
{

    import caurina.transitions.Tweener;

    import flash.display.Bitmap;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

    import org.kolonitsky.alexey.ui.SimpleButton;

    import view.events.GameEvent;

    public class MenuSkin extends Sprite
    {

        //-----------------------------
        // gameRunning
        //-----------------------------

        private var _gameRunning:uint;

        public function get gameRunning():uint
        {
            return _gameRunning;
        }

        public function set gameRunning(value:uint):void
        {
            _gameRunning = value;
            btnContinueGame.visible = value == 1;
            btnResult.visible = value == 1 || value == 2;
        }


        //-----------------------------
        // Constructor
        //-----------------------------

        public function MenuSkin()
        {
            imgLogo = new ImageAssets.LOGO_BITMAP;
            addChild(imgLogo);

            btnNewGame = new SimpleButton("", new ImageAssets.BTN_START_GAME_BITMAP);
            btnNewGame.addEventListener(MouseEvent.CLICK, btnNewGame_clickHandler);
            addChild(btnNewGame);

            btnContinueGame = new SimpleButton("", new ImageAssets.BTN_CONTINUE_GMAE_BITMAP);
            btnContinueGame.addEventListener(MouseEvent.CLICK, btnContinueGame_clickHandler);
            addChild(btnContinueGame);

            btnResult = new SimpleButton("", new ImageAssets.BTN_RESULT_BITMAP);
            btnResult.addEventListener(MouseEvent.CLICK, btnResult_clickHandler);
            addChild(btnResult);

            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
        }




        //-------------------------------------------------------------------
        //
        //  Private
        //
        //-------------------------------------------------------------------

        private var imgLogo:Bitmap;
        private var btnNewGame:SimpleButton;
        private var btnContinueGame:SimpleButton;
        private var btnResult:SimpleButton;

        private function addedToStageHandler(event:Event):void
        {
            var sw:Number = stage.stageWidth || stage.width;
            var sh:Number = stage.stageHeight || stage.height;

            var yPos:Number = Config.BOARD_TOP;
            imgLogo.x = (sw - imgLogo.width) / 2;
            imgLogo.y = 15;

            btnNewGame.x = Config.BOARD_LEFT;
            btnNewGame.y = yPos;
            yPos += btnNewGame.height + 10;

            btnContinueGame.x = Config.BOARD_LEFT;
            btnContinueGame.y = yPos;
            yPos += btnContinueGame.height + 10;

            btnResult.x = Config.BOARD_LEFT;
            btnResult.y = yPos;
            yPos += btnResult.height + 10;
        }

        private function btnNewGame_clickHandler(event:MouseEvent):void
        {
            dispatchEvent(new GameEvent(GameEvent.CREATE, true, false));
        }

        private function btnContinueGame_clickHandler(event:MouseEvent):void
        {
            dispatchEvent(new GameEvent(GameEvent.START, true, false));
        }

        private function btnResult_clickHandler(event:MouseEvent):void
        {
            dispatchEvent(new GameEvent(GameEvent.RESULT, true, false));
        }

    }
}
